\section{Question 1}

In this question, we are intended to find all the countries in the database where the Danube (called 'Donau' there for its German name) flows.
We must present the return of the query as follows :
\begin{verbatim}
<Countries_of_the_Danube>
   <name> ctry1 </name>
   <name> ctry2 </name>
   ...
   <name> ctryk </name>
</Countries_of_the_Danube>
\end{verbatim}
Where ctry\textit{i} are in alphabetical order.\\

We begin by extracting the list of countries present as attribute for the \verb?river? node which have a \verb?name? child node whose value is \textit{Donau}. XQuery equivalent is the following.
\begin{verbatim}
	let $x := tokenize(doc('/db/mondial/mondial-europe.xml')
    /mondial/river[name='Donau']/@country, "\s")
\end{verbatim} 

The \verb?tokenize()? function is necessary to split the string contained in \verb?river? attribute to create a list. Then we can check if a value is in that list.\\

To complete the request, we just have to get all countries having their attribute \verb?car_code? in the list ordered alphabetically. What corresponds to the following query :

\begin{verbatim}
for $c in doc('/db/mondial/mondial-europe.xml')/mondial/country
where $c/@car_code = $x
order by $c/name ascending
return $c/name
\end{verbatim}

After execution, the result is the following :

\begin{verbatim}
<Countries_of_the_Danube>
   <name>Austria</name>
   <name>Bulgaria</name>
   <name>Croatia</name>
   <name>Germany</name>
   <name>Hungary</name>
   <name>Moldova</name>
   <name>Romania</name>
   <name>Serbia</name>
   <name>Slovakia</name>
   <name>Ukraine</name>
</Countries_of_the_Danube>
\end{verbatim}

\section{Question 2}

In this question, we want to find all the countries through which the Danube doesn't flow, and where the population is at least 30 millions. For each response we must provide the \textit{car\_code} as attribute, the name and the population of the country as follows. Results must be ordered alphabetically by the country name.

\begin{verbatim}
<Big_countries_with_no_Danube>
   <country car_code="cc1">
      <name >c1</name>
      <population>p1 </population>
</country>
...
<country car_code="cck ">
      <name>ck </name>
      <population>pk </population>
   </country>
</Big_countries_with_no_Danube>
\end{verbatim}

As in the previous question, we need to find all the countries through which the Danube flows. Then we select all countries excluding those which are in the list. Finally, we restrict our selection to countries which have a population over 30 millions. Here is the corresponding \textit{XQuery} code :
\begin{verbatim}
let $x := tokenize(doc('/db/mondial/mondial-europe.xml')
    /mondial/river[name='Donau']/@country, "\s")
	
for $c in doc("/db/mondial-europe")/mondial/country[population >= 30000000]
where $c/@car_code != $x
order by $c/name ascending
\end{verbatim}

The query returns :

\begin{verbatim}
<Big_countries_with_no_Danube>
   <country car_code="F">
      <name>France</name>
      <population>58317450</population>
   </country>
   <country car_code="D">
      <name>Germany</name>
      <population>83536115</population>
   </country>
   <country car_code="I">
      <name>Italy</name>
      <population>57460274</population>
   </country>
   <country car_code="PL">
      <name>Poland</name>
      <population>38642565</population>
   </country>
   <country car_code="R">
      <name>Russia</name>
      <population>148178487</population>
   </country>
   <country car_code="E">
      <name>Spain</name>
      <population>39181114</population>
   </country>
   <country car_code="TR">
      <name>Turkey</name>
      <population>62484478</population>
   </country>
   <country car_code="UA">
      <name>Ukraine</name>
      <population>50864009</population>
   </country>
   <country car_code="GB">
      <name>United Kingdom</name>
      <population>58489975</population>
   </country>
</Big_countries_with_no_Danube>
\end{verbatim}

\section{Question 3}

In this question, we are searching for the southernmost city in France, excluding Corsica.
At first, we need to find all the continental french cities, ie those for which the province name are not "Corse" :

\begin{verbatim}
 let $f := doc('/db/mondial/mondialeurope.xml')
    /mondial/country[@car_code='F']/province[name!='Corse']/city
\end{verbatim}

As we must return all the southernmost cities, i.e. if there is more than one, all must appear, we do a loop on minimal latitude cities. 

\begin{verbatim}
  for $c in $f[latitude = min($f/latitude)]
     return <city> {$c/name}
                   {$c/latitude}
            </city>
\end{verbatim}

The query returns :

\begin{verbatim}
<Southernmost_city_in_continental_France>
   <city>
      <name>Marseille</name>
      <latitude>43.2</latitude>
   </city>
</Southernmost_city_in_continental_France>
\end{verbatim}


\section{Question 4}

	In this question we have to find the number of countries which share a border with Germany, excluding Germany itself, with the total and average population of these countries.\\
	
	To determine those countries, we have to get the \verb?country? node of Germany. Then we can get all the \verb?border? node and get their attribute \verb?car_code?. That corresponds to the following query :
	\begin{verbatim}
		let $countries := doc('/db/mondial/mondial-europe.xml')
		    /mondial/country[@car_code='D']/border/@country	
	\end{verbatim}

	After we can get all \verb?population? node for countries previously listed.
	\begin{verbatim}
	let $pop := doc('/db/mondial/mondial-europe.xml')
	    /mondial/country[@car_code=$countries]/population
	\end{verbatim}
	We now have all data we need to compute the answer thanks to aggregation function of \textit{XPath} \verb?count()?, \verb?sum()? and \verb?avg()?.
	
	\begin{verbatim}
	return <Info_on_countries_which_border_Germany
    country_count="{count($countries)}"
    pop_sum="{sum($pop)}"
    pop_avg="{avg($pop)}"
/> 
	\end{verbatim}
	
	The complete request is described below :
	\begin{verbatim}
let $countries := doc('/db/mondial/mondial-europe.xml')
    /mondial/country[@car_code='D']/border/@country
let $pop := doc('/db/mondial/mondial-europe.xml')
    /mondial/country[@car_code=$countries]/population
return <Info_on_countries_which_border_Germany
    country_count="{count($countries)}"
    pop_sum="{sum($pop)}"
    pop_avg="{avg($pop)}"
/>    
	\end{verbatim}
	
	When executed, it return the following xml data:
	\begin{verbatim}
	<Info_on_countries_which_border_Germany 
	    country_count="9" 
	    pop_sum="1.53915216E8" 
	    pop_avg="1.7101690666666668E7"
	/>
	\end{verbatim}